# encoding: utf-8

from pub.routine import TcpServer
# from pub.routine import UdpServer
from broker.routine import UdpImgServer as UdpServer
from broker.protocal import ForwardTrans, BROKER_PORT

if __name__ == "__main__":
    server = UdpServer(BROKER_PORT)
    protocal = ForwardTrans()
    server.set_protocal(protocal)
    server.listen(runHeart=True)

    while True:
        data = input("[Q] for quit: ")
        if data == "Q":
            server.stop()  # 关闭监听
            break
        elif data == "clear":
            protocal.dict_registers = {}
            protocal.map_connection = {}
        elif data == "list":
            from pprint import pprint
            print(">> 注册列表 <<")
            pprint(protocal.dict_registers)
            print(">> 连接映射 <<")
            pprint(protocal.map_connection)

    print("End")
